// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: taekwon

#pragma once

#include <memory>
#include <string>

#include "coin2/exchange/base/order/order.h"

#include "coin2/exchange/okex_common/api_util/auth_key.h"
#include "coin2/exchange/order/okex.pb.h"

namespace coin2::exchange::okex_futures::api_order {

class OkexFuturesNativePrivateClient : public coin2::exchange::base::order::NativePrivateClient {
 public:
  using RestParams = coin2::exchange::order::OkexFuturesRestParams;

 public:
  std::shared_ptr<AsioHttpContext> SubmitOrderExecution(const OrderExecutionProto& order);
  std::shared_ptr<AsioHttpContext> SubmitRestQuery(const RestQueryProto& query);

 public:
  OkexFuturesNativePrivateClient(const order::OrderConnectionConfig& config, bool is_swap);

  std::shared_ptr<AsioHttpContext> QueryAccountInfo();
  std::shared_ptr<AsioHttpContext> QueryProductAccountInfo(const std::string& instrument_id);
  std::shared_ptr<AsioHttpContext> QueryPositionInfo();
  std::shared_ptr<AsioHttpContext> QueryProductPositionInfo(const std::string& instrument_id);
  std::shared_ptr<AsioHttpContext> QueryOrders(const std::string& instrument_id, int state);
  std::shared_ptr<AsioHttpContext> PlaceOrder(const RestParams& params);
  std::shared_ptr<AsioHttpContext> CancelSingleOrder(const RestParams& params);
  std::shared_ptr<AsioHttpContext> CancelOrders(const RestParams& params);
  std::shared_ptr<AsioHttpContext> QueryFill(const std::string& instrument_id);

  std::string api_path_;
  std::string account_path_;
  std::string position_path_;
  std::string orders_path_;
  std::string transfer_path_;
  std::string place_order_path_;
  std::string cancel_order_path_;
  std::string cancel_multi_order_path_;
  std::string query_fill_path_;
  bool is_swap_;
  bool is_swap() { return is_swap_; }

  std::shared_ptr<AsioHttpContext> PlaceOrderNorm(const OrderExecution&) override;
  std::shared_ptr<AsioHttpContext> CancelOrderNorm(const OrderExecution&) override;

  RestParams GetRestOrderParams(const OrderSpec& order_spec, int64_t proc_order_id);
  RestParams GetRestCancelParams(const IOrderContext& order_context);

  std::shared_ptr<AsioHttpContext> QueryTransfer(const std::string& instrument_id,
      const std::string& type);
};

}  // namespace coin2::exchange::okex_futures::api_order
